package com.warehouse.service.impl;

import com.warehouse.entity.Customer;
import com.warehouse.mapper.CustomerMapper;
import com.warehouse.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public List<Customer> getAllCustomers() {
        return customerMapper.selectAll();
    }

    @Override
    public List<Customer> getActiveCustomers() {
        return customerMapper.selectActive();
    }

    @Override
    public Customer getCustomerById(Long id) {
        return customerMapper.selectById(id);
    }

    @Override
    public List<Customer> getCustomersByName(String customerName) {
        return customerMapper.selectByName(customerName);
    }

    @Override
    public List<Customer> getCustomersByPhone(String phone) {
        return customerMapper.selectByPhone(phone);
    }

    @Override
    @Transactional
    public Customer createCustomer(Customer customer) {
        customerMapper.insert(customer);
        return customer;
    }

    @Override
    @Transactional
    public Customer updateCustomer(Customer customer) {
        customerMapper.update(customer);
        return customer;
    }

    @Override
    @Transactional
    public boolean updateCustomerStatus(Long id, String status) {
        return customerMapper.updateStatus(id, status) > 0;
    }

    @Override
    @Transactional
    public boolean deleteCustomer(Long id) {
        return customerMapper.deleteById(id) > 0;
    }
    
    @Override
    public long getCustomerCount() {
        return customerMapper.countAll();
    }
} 